﻿Imports System.Text
Imports System.Security.Cryptography 'use for hashing
Imports System
Imports System.Data
Imports System.Data.OleDb

Partial Class CheckLogin
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Assume that access_db/Jobs.mdb exists in the root of hosting directory
        'Dim strDataSource As String = Server.MapPath("/access_db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the current directory
        Dim strDataSource As String = Server.MapPath("db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the parent directory of C: drive
        'Dim strDataSource As String = Server.MapPath("../access_db/Jobs.mdb")
        Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;Data source=" & strDataSource
        Dim objConnection As OleDbConnection = New OleDbConnection(strConnection)
        objConnection.Open()

        Dim strLoginName As String = Request.QueryString("loginName")
        Dim strLoginPass As String = Request.QueryString("loginPass")
        Dim strTableName As String = Request.QueryString("tableName")
        Dim strSQL As String = "SELECT * FROM " + strTableName + " WHERE Trim(loginName) = '" + Trim(strLoginName) + _
                                "' AND Trim(loginPassword) = '" + Trim(strLoginPass) + "'"
        'MsgBox(strSQL)
        Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
        objCommand.CommandType = CommandType.Text
        Dim userId As String = ""
        Dim strResultsHolder As String = ""

        Dim objReader As OleDbDataReader
        Try
            objReader = objCommand.ExecuteReader()
            If objReader.HasRows Then
                strResultsHolder = "true,"
            Else
                strResultsHolder = "false,"
            End If
            If strTableName = "tblEmployers" Then
                strResultsHolder = strResultsHolder & "employerLoginDiv,tblEmployers,"
                userId = "employerId"
            ElseIf strTableName = "tblJobSeekers" Then
                strResultsHolder = strResultsHolder & "jobSeekerLoginDiv,tblJobSeekers,"
                userId = "jobSeekerId"
            Else
                strResultsHolder = strResultsHolder & "adminLoginDiv,tblAdmin,"
                userId = "adminId"
            End If

            ' Always call Read before accessing data.
            While objReader.Read()
                strResultsHolder = strResultsHolder & objReader(userId).ToString() & "@"
            End While

            ' always call Close when done reading.
            objReader.Close()
            objConnection.Close()
            objConnection.Dispose()
            'MsgBox("StrResultsHolder = " & strResultsHolder)
            Response.Write(strResultsHolder)
            'MsgBox(strResultsHolder)
        Catch ex As OleDb.OleDbException
            Response.Write(ex.Message())
        End Try

        ' Close the connection when done with it.
        'objConnection.Close()

    End Sub
End Class